package com.unicom.projt;

import android.content.Intent;
import android.widget.EditText;
import com.unicom.projt.fee.PaymentConfirmPage;
import com.unicom.projt.fee.PaymentSuccessPage;
import com.unicom.projt.http.AbstractHttpController;
import com.unicom.projt.http.UriConstants;
import com.unicom.projt.reg.RegisterStepOnePage;
import com.unicom.projt.reg.RegisterStepTwoPage;
import com.unicom.projt.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: Lee
 * Date: 12-2-19
 * Time: 下午7:26
 */
public class InputPhoneNumberController extends AbstractHttpController<String> {
    private InputPhoneNumberPage inputPhoneNumberPage;

    public InputPhoneNumberController(InputPhoneNumberPage inputPhoneNumberPage) {
        super(String.class);
        this.inputPhoneNumberPage = inputPhoneNumberPage;
    }

    @Override
    public void onNetworkAbort() {
        ToastUtils.showMessage(inputPhoneNumberPage, "错误，网络连接被中断.");
        inputPhoneNumberPage.hideProgressDialog();
    }

    @Override
    public void onNetworkError() {
        ToastUtils.showMessage(inputPhoneNumberPage, "错误，网络连接错误.");
        inputPhoneNumberPage.hideProgressDialog();
    }

    @Override
    public void onRequestFinish(String response) {
        inputPhoneNumberPage.hideProgressDialog();
        if (response == null || "".equals(response)) {
            ToastUtils.showMessage(inputPhoneNumberPage, "错误，请稍候再试");
            return;
        }
        String respCode = SimpleXmlParser.getResponseCode(response);
        if (ResponseCode.USER_NOT_EXIST.equals(respCode)) {
            PageJumpUtils.jump(inputPhoneNumberPage, RegisterStepOnePage.class);
            inputPhoneNumberPage.finish();
        } else if (ResponseCode.NOT_UNICOM_NUMBER.equals(respCode)) {
            ToastUtils.showMessage(inputPhoneNumberPage, "错误," + SimpleXmlParser.getResponseDes(response));
        } else {
            PageJumpUtils.jump(inputPhoneNumberPage, Main.class);
            inputPhoneNumberPage.finish();
        }
    }

    @Override
    public void onResponseError() {
        ToastUtils.showMessage(inputPhoneNumberPage, "错误，返回结果错误.");
        inputPhoneNumberPage.hideProgressDialog();
    }

    public void checkPhoneNumberAndJumpToPage(String phoneNumber) {
        UserHolder.phoneNumber=phoneNumber;
        String checkPhoneNumberXml = new PostXmlBuilder().setBiPCode(RequestCode.VERIFY_PHONE_NUMBER).setTelNo(phoneNumber).createXml();
        this.sendRequest(UriConstants.URL, checkPhoneNumberXml);
//        PageJumpUtils.jump(inputPhoneNumberPage,Home.class);

//        Intent intent = new Intent(inputPhoneNumberPage, PaymentSuccessPage.class);
//        intent.putExtra("amount", "222");
//        intent.putExtra("phoneNumber", "12333333");
//        intent.putExtra("orderId", "444");
//        inputPhoneNumberPage.startActivity(intent);
//        inputPhoneNumberPage.finish();
    }
}
